const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const BookInstanceSchema = new Schema({
    book: { type: Schema.Types.ObjectId, ref: 'Book', required: true },
    imprint: { type: String, required: true },
    status: {
        type: String,
        required: true,
        enum: ['可借', '馆藏维护', '已借出', '已预留'],
        default: '馆藏维护'
    }
});

// 虚拟属性：藏书URL
BookInstanceSchema.virtual('url').get(function () {
    return '/catalog/bookinstance/' + this._id;
});

// 导出 BookInstance 模型
module.exports = mongoose.model('BookInstance', BookInstanceSchema);
